<?php
include '../classes/Authentication.php';
include '../classes/HTML.php';
session_start ();
$auth = new Authentication ();
$auth->checkAuthentication ($_SERVER['PHP_SELF'], 1);
HTML::createHeader('Benutzer erstellen', 'users_create.css');
$db = new DB_For_User();
?>
<body>
	<?php HTML::createLogobar($auth->getUser());?>
	<div class="container">
		<div class="row">
			<div class="col-md-3">
				<h3>Infos</h3>
				<p>Zur&uuml;ck zur &Uuml;bersicht:</p>
				<form method="post" action="tickets.php">
					<button type="submit" name="back" class="btn btn-default">Zur&uuml;ck &raquo;</button>
				</form>
			</div>
			<div class="col-md-4">
				<h2>Kommentare</h2>
				<?php 
					if(isset($_POST['submit'])) {
							if($db->insertComment($_POST['ticket_id'], $_SESSION['user_ID'], $_POST['description']))
								header('Location: tickets_comments.php?id=' . $_POST['ticket_id']);
							else 
								echo '<p style="color: red;">Fehler beim Erstellen, bitte Versuchen Sie es erneut</p>';
					}
					if(isset($_GET['id'])) {
						$comments = $db->getComments($_GET['id']);
						foreach($comments as $comment) {
							echo '<input readonly="readonly" type="text" class="form-group" value="' . $comment['email'] . '" /><br/>';
							echo '<textarea readonly="readonly">' . $comment['value'] . '</textarea>';
							echo '<hr>';
						}
					}
					if(isset($_POST['ticket_id'])) {
						$comments = $db->getComments($_POST['ticket_id']);
						foreach($comments as $comment) {
							echo '<input readonly="readonly" type="text" class="form-group" value="' . $comment['email'] . '" /><br/>';
							echo '<textarea readonly="readonly">' . $comment['value'] . '</textarea>';
							echo '<hr>';
						}
					}
				?>
				<p>Erstellen Sie hier einen neuen Kommentar:</p>
				<form method="post" action="tickets_comments.php">
					<div class="form-group">
						<textarea rows="5" name="description" placeholder="Schreiben Sie hier eine Kurze Beschreibung" class="form-control" value="" required><?php if(isset($_POST['description'])) echo $_POST['description'] ?></textarea>
					</div>
					<input type="hidden" name="ticket_id" value="<?php if(isset($_GET['id'])) echo $_GET['id']; if(isset($_POST['ticket_id'])) echo $_POST['ticket_id']; ?>" />
					<button type="submit" name="submit" class="btn btn-default">Erstellen &raquo;</button>
				</form>
			</div>
		</div>
		<?php HTML::createFooter();?>
	</div>
	<?php HTML::includeJS();?>
</body>
</html>